package com.sitech.ibnms.util.charts.fusion.thermometer;

import java.util.HashMap;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.sitech.ibnms.util.charts.fusion.FusionChartCommon;
import com.sitech.ibnms.util.charts.fusion.pie.FusionPieChartParamName;
import com.sitech.ibnms.util.charts.fusion.pie.FusionPieChartParameter;

/**
 * @author Mirror_Jean
 *
 * @Date :Jan 11, 2011
 * @Time :2:35:36 PM
 * @Vesion :FusionThermChart
 */
public class FusionThermChart {

	public String getThermChart(FusionThermChartParameter parameter,
			String value ) {
		
		return  FusionChartCommon.getScript(parameter).replaceAll("######", 
				this.setThermChartParameter(parameter, value).toString());
	}
	
	public String setThermChartParameter(FusionThermChartParameter parameter,
			String value ) {
		Document document = DocumentHelper.createDocument();
		try {
			Element chartHead = document.addElement("chart");
			String headAttribute[] = FusionThermChartParamName.paramName;
			String headAttributeValue[] = FusionThermChartParameter.getParamVaule(parameter,headAttribute);
			int idx = 0;
			for (String name : headAttribute) {
				chartHead.addAttribute(name, headAttributeValue[idx]);
				idx++;
			}
			setValue(chartHead,value);
		} catch (Exception ex) {
			System.out.println("add root chart has exception ,method : setLineChartParameter();");
			ex.printStackTrace();
		}
		return formatXMLData(document);
	}
	
	private void setValue(Element parentEl, String value){
		Element chartNode = parentEl.addElement("value");
		chartNode.addText(value);
	}
	
	private void setAnnotations(){
		
	}
	
	private String formatXMLData(Document document) {
		String xml[] = document.asXML().split("\n");
		System.out.println("xml size : " + xml.length);
		return xml[1].replace("\"", "\'");
	}
}
